package com.funcablaze.tpxterm.func;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;

public class BaseFile extends File {
	public BaseFile(@NotNull String pathname) {
		super(pathname);
	}
	
	public BaseFile(BaseFile baseFile, String string) {
		super(baseFile, string);
	}
	
	@Nullable
	@Override
	public BaseFile[] listFiles() {
		File[] files = super.listFiles();
		if (files == null) return null;
		BaseFile[] baseFiles = new BaseFile[files.length];
		for (int i = 0; i < files.length; i++) {
			baseFiles[i] = new BaseFile(files[i].getPath());
		}
		return baseFiles;
	}
	
	@Override
	public @NotNull String getAbsolutePath() {
		return super.getAbsolutePath().replace('\\', '/');
	}
	
	@Override
	public int compareTo(@NotNull File o) {
		// 文件夹在上，文件在下，按名称排序
		return isDirectory() == o.isDirectory() ? getName().compareTo(o.getName()) : isDirectory() ? -1 : 1;
	}
}
